package org.upt.dcda.presentation;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.upt.dcda.OrderManager;
import org.upt.dcda.OrderManagerBeanRemote;
import org.upt.dcda.db.OrderEntity;

public class OrderInformation
{

	@EJB
	OrderManagerBeanRemote	orderManagerBean;

	public List<OrderEntity> viewAllOrders(HttpServletRequest request,
			HttpServletResponse response)
	{
		List<OrderEntity> orders = null;
		try
		{
			InitialContext initContext = new InitialContext();
			this.orderManagerBean = (OrderManagerBeanRemote) initContext
					.lookup(OrderManager.ORDER_BEAN_NAME);

			orders = this.orderManagerBean.viewAllOrders();
		}
		catch (Throwable be)
		{
			try
			{
				request.getServletContext().log("Caught Exception: " + be, be);
				response.sendError(
						HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
						be.toString());
			}
			catch (IOException e)
			{
				request.getServletContext().log("Caught IOException: " + e, e);
			}
		}
		return orders;
	}
}
